package org.hackystat.devcathlon.ui.page.commons.panels.date;

import java.util.Date;
import java.util.Locale;

import org.apache.wicket.Session;
import org.apache.wicket.datetime.StyleDateConverter;
import org.apache.wicket.datetime.markup.html.form.DateTextField;
import org.apache.wicket.extensions.yui.calendar.DatePicker;
import org.apache.wicket.feedback.ComponentFeedbackMessageFilter;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.PropertyModel;

/**
 * Date picker panel.
 * @author Anthony Du
 */
public class DatePickerPanel extends Panel {
  /** Support serialization. */
  private static final long serialVersionUID = 1L;
  /** Locale English. */
  private static final Locale LOCALE_EN = new Locale("en");
  /** Date object. */
  private final Date date = new Date();
  /** Selected Locale. */
  private Locale selectedLocale = LOCALE_EN;

  /**
   * Constructs Date picker panel.
   * 
   * @param id
   *          The panel id
   */
  public DatePickerPanel(String id) {
    super(id);

    selectedLocale = Session.get().getLocale();
    DateTextField dateTextField = new DateTextField("dateTextField",
        new PropertyModel(this, "date"), new StyleDateConverter("S-", true)) {
      /** Support Serialization. */
      private static final long serialVersionUID = 1L;

      @Override
      public Locale getLocale() {
        return selectedLocale;
      }
    };
    Form form = new Form("form") {
      /** Support Serialization. */
      private static final long serialVersionUID = 1L;

      @Override
      protected void onSubmit() {
        info("set date to " + date);
      }
    };
    add(form);
    form.add(dateTextField);
    dateTextField.add(new DatePicker());
    add(new FeedbackPanel("feedback", new ComponentFeedbackMessageFilter(form)));
  }
}